<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>dingtalk-login</title>
</head>
<body>
<p>
    当前登录用户: ${currUser.username} 。
    <#if currUser.bindingDingtalk>
        <a href="/unbinding-dingtalk">已经绑定(点击解绑)</a>
    <#else>
        <a href="#" onclick="binding()">未绑定</a>
    </#if>
    <a href="/logout">注销</a>
</p>
<script>
    function binding(){

        let redirectUri = location.protocol + "//" + location.host + "/dingtalk/auth";

        let url = "https://login.dingtalk.com/oauth2/auth" +
            "?redirect_uri=" + encodeURIComponent(redirectUri) +
            "&response_type=code" +
            "&client_id=${dingtalk.appKey}" +
            "&scope=openid" +
            "&prompt=consent" +
            "&state=BINDING";
        location.href = url;
    }
</script>
</body>
</html>